package page;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.concurrent.TimeUnit;

/**
 * Created by User on 26/05/2014.
 */
public class HomePage {
    private final String URL = "http://rozetka.com.ua/";
    public static WebDriver driver;

    @FindBy (how = How.ID, using = "computers-notebooks")
    protected WebElement computers_notebooks;
    @FindBy (how = How.ID, using = "phones-mp3-gps")
    protected WebElement phones_mp3_gps;
    @FindBy (how = How.ID, using = "tv-photo-video")
    protected WebElement tv_photo_video;
    @FindBy (how = How.ID, using = "bt")
    protected WebElement bt;
    @FindBy (how = How.ID, using = "outdoorsman")
    protected WebElement outdoorsman;
    @FindBy (how = How.ID, using = "kids")
    protected WebElement kids;
    @FindBy (how = How.ID, using = "house_garden")
    protected WebElement house_garden;
    @FindBy (how = How.ID, using = "273290")
    protected WebElement n;
    @FindBy (how = How.ID, using = "fatmenu_14")
    protected WebElement fatmenu_14;
    @FindBy (how = How.ID, using = "shoes")
    protected WebElement shoes;


    protected WebElement project;

//"computers-notebooks" "phones-mp3-gps" "tv-photo-video"  "bt"  "outdoorsman"  "kids"   "house_garden"  "273290"  "fatmenu_14"  "shoes"
    public HomePage (WebDriver driver){
        this.driver = driver;
        PageFactory.initElements(driver,this);
    }

    public void open()
    {
        driver.get(URL);
    }

    public WebElement getMenuItem(String name)
    {
        WebDriverWait wait = new WebDriverWait(driver, 20);
        wait.until(ExpectedConditions.elementToBeClickable(project));
        if (name=="computers_notebooks")
            return computers_notebooks;
        else if (name=="phones-mp3-gps")
                return phones_mp3_gps;
        else if (name=="tv-photo-video")
                return tv_photo_video;
        else if (name=="bt")
                return bt;
        else if (name=="outdoorsman")
                return outdoorsman;
        else if (name=="kids")
                return kids;
        else if (name=="house_garden")
                return house_garden;
        else if (name=="273290")
                return n;
        else if (name=="fatmenu_14")
                return fatmenu_14;
        else if (name=="shoes")
                return shoes;
        return null;
    }

    public void waiting()
    {
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

}
